package com.ler.demo.entity;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.extension.activerecord.Model;
import com.ler.demo.mapper.UserAddressMapper;
import com.ler.demo.mapper.UserClassMapper;
import com.ler.demo.mapper.UserHobbyMapper;
import com.ler.demo.mapper.UserMidClassMapper;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import java.io.Serializable;
import java.util.List;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;
import top.lww0511.extra.annotation.Many2Many;
import top.lww0511.extra.annotation.One2Many;
import top.lww0511.extra.annotation.One2One;

/**
 * <p>
 * 用户相关
 * </p>
 *
 * @author lww
 * @since 2021-03-11
 */
@Data
@EqualsAndHashCode(callSuper = false)
@Accessors(chain = true)
@ApiModel(value = "UserAccount对象", description = "用户相关")
public class UserAccount extends Model<UserAccount> {

    private static final long serialVersionUID = 1L;

    @ApiModelProperty(value = "id")
    @TableId(value = "id", type = IdType.AUTO)
    private Long id;

    @ApiModelProperty(value = "昵称")
    private String nickName;

    @TableField(exist = false)
    //把id的值 作为userId  在 UserAddressMapper中 查询
    @One2One(self = "id", as = "user_id", mapper = UserAddressMapper.class)
    private UserAddress address;

    @TableField(exist = false)
    @One2Many(self = "id", as = "user_id", mapper = UserHobbyMapper.class)
    private List<UserHobby> hobbies;

    @TableField(exist = false)
    @Many2Many(self = "id", leftMid = "user_id", rightMid = "class_id", origin = "id"
            , midMapper = UserMidClassMapper.class, mapper = UserClassMapper.class)
    private List<UserClass> classes;

    @Override
    protected Serializable pkVal() {
        return this.id;
    }

}
